package servlets;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import utils.WebUtils;
import xml.RespuestaXML;
import dtos.ModuloDTO;
import dtos.ServiciosModuloDTO;
import dtos.SolicitudDTO;

/**
 * Servlet implementation class BuscarSolicitudesPendientes
 */
@WebServlet("/BuscarSolicitudesPendientes")
public class BuscarSolicitudesPendientes extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private bd.BusinessDelegate bd = null;
	private List<SolicitudDTO> resultado;
	
	   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuscarSolicitudesPendientes() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
    	PrintWriter out = response.getWriter();
		out.println("<table width='100%' cellspacing='5' cellpading='5'>");
		resultado = bd.getInstance().getSolicitudesPendientes();
		if(!resultado.isEmpty()){
			for(SolicitudDTO s : resultado){
				ModuloDTO m = s.getDeposito();
				out.println("<tr width='100%'>");
				if(s != null){
					out.println("<td width='33%'>"+s.getId()+"</td>");
					out.println("<td width='33%'>"+m.getNombre()+"</td>");
					out.println("<td width='33%'>PENDIENTE</td>");
				}
			}
		}
		
		resultado = bd.getInstance().getSolicitudesPorEstado(1);
		if(!resultado.isEmpty()){
			for(SolicitudDTO s : resultado){
				ModuloDTO m = s.getDeposito();
				out.println("<tr width='100%'>");
				if(s != null){
					out.println("<td width='33%'>"+s.getId()+"</td>");
					out.println("<td width='33%'>"+m.getNombre()+"</td>");
					out.println("<td width='33%'>PROCESADA Y ENVIADA</td>");
				}
			}
		}
		
		out.println("</table>");

	}

}
